package org.liveboardgames.agricola.control.delegates.mock.cards.actioncards
{
    import mx.collections.ArrayCollection;
    import mx.collections.ListCollectionView;
    
    import org.liveboardgames.agricola.control.delegates.mock.ActionFactory;
    import org.liveboardgames.agricola.model.enums.ActionOutputEnum;
    import org.liveboardgames.agricola.model.enums.HouseTypeEnum;
    import org.liveboardgames.agricola.model.enums.PrerequisiteEnum;
    import org.liveboardgames.agricola.model.enums.ResourceTypeEnum;
    import org.liveboardgames.agricola.model.enums.ResourceZoneEnum;
    import org.liveboardgames.agricola.view.component.ImageHandler;
    import org.liveboardgames.agricola.vo.action.Action;
    import org.liveboardgames.agricola.vo.card.ActionCard;
    
    [Bindable]
    public class FivePlayersFamilyCards
    {
        public static const FOUR_WOOD:ActionCard = getFourWoodCard();
        
        public static const TWO_BUILD_OR_BIRTH:ActionCard = getTwoBuildOrBirthCard();
        
        public static const TRAVELING_PLAYER_OR_ROOM:ActionCard = getTravelingPlayerOrRoomCard();
        
        public static const THREE_CLAY:ActionCard = getThreeClayCard();
        
        public static const REED_WOOD_STONE:ActionCard = getReedWoodStoneCard();
        
        public static const ANIMALS:ActionCard = getAnimalsCard();
        
        private static function getFourWoodCard():ActionCard
        {
            var card:ActionCard = new ActionCard();
            card.cardName = "Four wood";
            card.imagePath = ImageHandler.FIVE_PLAYERS_FAMILY + "FourWood.png";
            card.resourceZone = ResourceZoneEnum.BOTTOM;
            
            // Build the actions
            var actions:ListCollectionView = new ArrayCollection();
            
            // Accumulation of resources
            var action:Action = ActionFactory.getResourceAction(ActionOutputEnum.WOOD, 4, true);
            action.target = card;
            action.needPlayerInput = false;
            
            // A peep can take all accumulated resources
            var takeAction:Action = ActionFactory.getTakeAllAction(card);
            
            actions.addItem(action);
            actions.addItem(takeAction);
            card.actions = actions;
            
            return card;
        }
        
        private static function getThreeClayCard():ActionCard
        {
            var card:ActionCard = new ActionCard();
            card.cardName = "Three clay";
            card.imagePath = ImageHandler.FIVE_PLAYERS_FAMILY + "ThreeClay.png";
            card.resourceZone = ResourceZoneEnum.BOTTOM;
            
            // Build the actions
            var actions:ListCollectionView = new ArrayCollection();
            
            // Accumulation of resources
            var action:Action = ActionFactory.getResourceAction(ActionOutputEnum.CLAY, 3, true);
            action.target = card;
            action.needPlayerInput = false;
            
            // A peep can take all accumulated resources
            var takeAction:Action = ActionFactory.getTakeAllAction(card);
            
            actions.addItem(action);
            actions.addItem(takeAction);
            card.actions = actions;
            
            return card;
        }
        
        private static function getReedWoodStoneCard():ActionCard
        {
            var card:ActionCard = new ActionCard();
            card.cardName = "Reed, Wood, Stone";
            card.imagePath = ImageHandler.FIVE_PLAYERS_FAMILY + "ReedStoneWood.png";
            card.resourceZone = ResourceZoneEnum.CENTER;
            
            // Build the actions
            var actions:ListCollectionView = new ArrayCollection();
            
            // Accumulation of resources
            var reed:Action = ActionFactory.getResourceAction(ActionOutputEnum.REED, 1, true);
            reed.target = card;
            reed.needPlayerInput = false;
            var stone:Action = ActionFactory.getResourceAction(ActionOutputEnum.STONE, 1, false);
            stone.needPlayerInput = false;
            var wood:Action = ActionFactory.getResourceAction(ActionOutputEnum.WOOD, 1, false);
            wood.needPlayerInput = false;
            
            // A peep can take all accumulated resources
            var takeAction:Action = ActionFactory.getTakeAllAction(card);
            
            actions.addItem(reed);
            actions.addItem(stone);
            actions.addItem(wood);
            actions.addItem(takeAction);
            card.actions = actions;
            
            return card;
        }
        
        private static function getAnimalsCard():ActionCard
        {
            var card:ActionCard = new ActionCard();
            card.cardName = "Animals";
            card.imagePath = ImageHandler.FIVE_PLAYERS_FAMILY + "Animals.png";
            
            // Build the actions
            var actions:ListCollectionView = new ArrayCollection();
            
            var sheepAction:Action = ActionFactory.getResourceAction(ActionOutputEnum.SHEEP, 1, false);
            sheepAction.target = card;
            // Negative cost to mean we get one food in addition... strange, may work though
            sheepAction.cost = ResourceTypeEnum.getResourceAsMap(ResourceTypeEnum.FOOD, -1);
            
            var boarAction:Action = ActionFactory.getResourceAction(ActionOutputEnum.BOAR, 1, false);
            boarAction.target = card;
            
            var cattleAction:Action = ActionFactory.getResourceAction(ActionOutputEnum.CATTLE, 1, false);
            cattleAction.target = card;
            cattleAction.cost = ResourceTypeEnum.getResourceAsMap(ResourceTypeEnum.FOOD, 1);
            
            // Make sure that it is one action or the other
            var exclusiveActions:ListCollectionView = new ArrayCollection();
            exclusiveActions.addItem(sheepAction);
            exclusiveActions.addItem(boarAction);
            exclusiveActions.addItem(cattleAction);
            
            actions.addItem(sheepAction);
            actions.addItem(boarAction);
            actions.addItem(cattleAction);
            
            card.actions = actions;
            card.exclusiveActions = exclusiveActions;
            
            return card;
        }
        
        private static function getTravelingPlayerOrRoomCard():ActionCard
        {
            var card:ActionCard = new ActionCard();
            card.cardName = "Traveling Player or Room";
            card.resourceZone = ResourceZoneEnum.BOTTOM;
            card.imagePath = ImageHandler.FIVE_PLAYERS_FAMILY + "TravelingPlayer.png";
            
            // Build the actions
            var actions:ListCollectionView = new ArrayCollection();
            
            var woodenRoomAction:Action = ActionFactory.getRoomAction(HouseTypeEnum.WOODEN);
            var clayRoomAction:Action = ActionFactory.getRoomAction(HouseTypeEnum.CLAY);
            var stoneRoomAction:Action = ActionFactory.getRoomAction(HouseTypeEnum.STONE);
            
            var foodAction:Action = ActionFactory.getResourceAction(ActionOutputEnum.FOOD, 1, true);
            foodAction.target = card;
            foodAction.needPlayerInput = false;
            var takeAction:Action = ActionFactory.getTakeAllAction(card);
            takeAction.needPlayerInput = true;
            
            // Make sure that it is one action or the other
            var exclusiveActions:ListCollectionView = new ArrayCollection();
            exclusiveActions.addItem(woodenRoomAction);
            exclusiveActions.addItem(clayRoomAction);
            exclusiveActions.addItem(stoneRoomAction);
            exclusiveActions.addItem(takeAction);
            
            actions.addItem(woodenRoomAction);
            actions.addItem(clayRoomAction);
            actions.addItem(stoneRoomAction);
            actions.addItem(foodAction);
            actions.addItem(takeAction);
            
            card.actions = actions;
            card.exclusiveActions = exclusiveActions;
            
            return card;
        }
        
        private static function getTwoBuildOrBirthCard():ActionCard
        {
            var card:ActionCard = new ActionCard();
            card.cardName = "Two building materials or birth";
            card.imagePath = ImageHandler.FIVE_PLAYERS_FAMILY + "TwoBuildingMaterialOrBirth.png";
            
            // Build the actions
            var actions:ListCollectionView = new ArrayCollection();
            
            var twoBuildingMaterialsAction:Action = ActionFactory.getResourceAction(ActionOutputEnum.CHOICE_RESOURCE, 2);
            var birthAction:Action = ActionFactory.getBirthAction();
            birthAction.link = card;
            birthAction.addPrerequisite(PrerequisiteEnum.ROUND_FIVE);
            
            var exclusiveActions:ListCollectionView = new ArrayCollection();
            exclusiveActions.addItem(twoBuildingMaterialsAction);
            exclusiveActions.addItem(birthAction);
            
            actions.addItem(twoBuildingMaterialsAction);
            actions.addItem(birthAction);
            
            card.actions = actions;
            card.exclusiveActions = exclusiveActions;
            
            return card;
        }
    }

}